package game;

import java.awt.Graphics;
import java.awt.geom.Point2D;
import java.util.LinkedList;
import java.util.Random;

public class GerParticula {

	static private GerParticula instance = null;
	
	private LinkedList<Particula> listParticula = new LinkedList<Particula>();

	public static GerParticula getInstance() {
		
		if(instance == null)
		{
			instance =  new GerParticula();
		}
		
		return instance;
	}
	
	int numParticulas = 10;
	Random random = new Random();
	
	public void update()
	{
		
		for(int i = 0; i < numParticulas; i++)
		{
			double x = random.nextDouble() * 2;
			double y = random.nextDouble() * 2;
			if(x < 1)
				x *= -1;
			else
				x -= 1;
			if(y < 1)
				y *= -1;
			else
				y -= 1;
			
			this.listParticula.add(new Particula(	new Point2D.Double(Mouse.getInstance().getPositionMouse().getX(), Mouse.getInstance().getPositionMouse().getY()),
													new Point2D.Double(10, 10),
													1,
													new Point2D.Double(x, y),
													-10 + random.nextInt(20)));
		}
		
		for(int i = 0; i < listParticula.size(); i++)
		{
			if(listParticula.get(i).getLife() == false)
				listParticula.remove(i);
			listParticula.get(i).update();
		}
	}

	public void draw(Graphics graphic)
	{
		for(Particula obj:listParticula)
			obj.draw(graphic);
	}
}
